const express = require('express');
const router = express.Router();

router.get('/topLevel', (req, res) => {
    const content = [];
    for(let i = 0; i < 10; i++) content.push({
        id: `id${i}`,
        code: `513200${i}`,
        name: `name${i}`,
        remark: `remark${i}`,
        isLeaf: true,
        rowVersion: 'rowVersion',
        options: ['update', 'abandon']
    });

    res.json({
        message: 'ok',
        payload: {
            content,
            totalElements: 10,
        }
    });
});

router.get('/:id/children', (req, res) => {
    const content = [];
    for(let i = 0; i < 10; i++) content.push({
        id: `id${i}`,
        code: `513200${i}`,
        name: `name${i}`,
        remark: `remark${i}`,
        isLeaf: true,
        rowVersion: 'rowVersion',
        options: ['update', 'abandon']
    });

    res.json({
        message: 'ok',
        payload: {
            content,
            totalElements: 10,
        }
    });
});

router.post('/', (req, res) => {
    res.json({
        message: '新增成功'
    });
});

router.put('/:id', (req, res) => {
    res.json({
        message: '修改成功'
    });
});

router.put('/:id/abandon', (req, res) => {
    res.json({
        message: '作废成功'
    });
});


// eslint-disable-next-line func-style
function mockData(id) {
    const data = [];
    for(let i = 1; i < 10; i++)
        data.push({
            id: `${id}-${i}`,
            code: `Code-${id}-${i}`,
            name: `Name-${id}-${i}`,
            remark: `Remark${i}`,
            isLeaf: i % 3 === 2 || i % 4 === 0,
            options: [
                'update',
                'abandon',
            ],
            rowVersion: 'rowVersion'
        });
    
    return data;
}

router.get('/:id/children', (req, res) => {
    const {pageIndex, pageSize} = req.query;
    res.json({
        payload: {
            content: mockData(req.params.id)
        }
    });
});

router.get('/topLevel', (req, res) => {
    res.json({
        payload: {
            content: [{
                id: '1',
                code: 'Code-1',
                name: 'Name-1',
                remark: 'Remark-1Remark-1Remark-1Remark-1Remark-1Remark-1Remark-1Remark-1Remark-1Remark-1Remark-1',
                isLeaf: false,
                rowVersion: 'rowVersion',
                options: [
                    'update',
                    'abandon',
                ],
            }, {
                id: '2',
                code: 'Code-2',
                name: 'Name-2',
                remark: 'Remark-2',
                isLeaf: false,
                rowVersion: 'rowVersion',
                options: [
                    'update',
                    'abandon',
                ],
            }, {
                id: '3',
                code: 'Code-3',
                name: 'Name-3',
                remark: 'Remark-3',
                isLeaf: false,
                rowVersion: 'rowVersion',
                options: [
                    'update',
                    'abandon',
                ],
            }, {
                id: '4',
                code: 'Code-4',
                name: 'Name-4',
                remark: 'Remark-4',
                isLeaf: false,
                rowVersion: 'rowVersion',
                options: [
                    'update',
                    'abandon',
                ],
            }, {
                id: '5',
                code: 'Code-5',
                name: 'Name-5',
                remark: 'Remark-5',
                isLeaf: false,
                rowVersion: 'rowVersion',
                options: [
                    'update',
                    'abandon',
                ],
            }]
        }
    });
});
/**
 * @param {Object} options
 * @throws {Error}
 * @return {Promise}
 */
let count = 1722;
router.post('/', async(req, res, next) => {
    count += 1;
    const options = {
    };
    const data = {
        message: 'message',
        payload: {
            id: `id${count}`,
            rowVersion: 'rowVersion',
            options: [
                'update',
                'abandon',
            ]
        }
    };
    res.json(data);
});
/**
 * @param {Object} options
 * @param {} options.id 维修项目分类Id
 * @throws {Error}
 * @return {Promise}
 */
router.put('/:id', async(req, res, next) => {
    const options = {
        id: req.params.id
    };
    const data = {
        message: 'message',
        payload: {
            rowVersion: 'rowVersion',
            options: [
                'update',
                'abandon',
            ],
        }
    };
    res.json(data);
});
/**
 * @param {Object} options
 * @param {} options.id 维修项目分类Id
 * @throws {Error}
 * @return {Promise}
 */
router.put('/:id/abandon', async(req, res, next) => {
    const options = {
        id: req.params.id
    };
    const data = {
        message: 'message',
        payload: {
            rowVersion: 'rowVersion'
        }
    };
    res.json(data);
});
module.exports = router;
